package com.wsd.common;

import com.wsd.constant.ResultCode;

/**
 * @author  zhangqizeng
 * 通用 结果返回类
 */
public class Result {
    //请求是否成功
    private boolean success;
    // 结果状态码
    private Integer code;
    // 结果消息
    private String msg;
    // 结果数据 这个data尽量是标准的JSONObject （Map list 都能转换成JSONObject）
    private Object data;

    public Result() {
        super();
    }

    public Result(boolean success,Integer code, String msg, Object data) {
        this.success = success;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 根据状态码枚举设置状态码和状态信息的值
     * @param code 状态码枚举
     */
    public void setResultCode(ResultCode code) {
        this.code = code.getCode();
        this.msg = code.getMessage();
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }


    @Override
    public String toString() {
        return "Result{" +
                "success=" + this.success +
                "code=" + this.code +
                ", msg='" + this.msg + '\'' +
                ", data=" + this.data +
                '}';
    }

}
